package com.mspbots.sync.wise;

import com.mspbots.sync.wise.client.ClientProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;

/**
 * SyncStartAndEndController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/6/18
 */
@Log4j2
@RestController
@RequiredArgsConstructor
public class WiseController {

    private final WiseSyncScheduled syncService;
    private final WiseSyncService wiseSyncService;

    @PostMapping(path = "exists/connect")
    public Mono<Object> existsConnect(@RequestBody ClientProperties requestParams) {
        return wiseSyncService.existsConnect(requestParams);
    }

    @GetMapping(path = "connect/ready")
    public Mono<Object> connectReady(@RequestParam Integer tenantId) {
        return this.wiseSyncService.connectReady(tenantId);
    }

    @GetMapping(path = "manual/sync")
    public Flux<Object> manualSync(@RequestParam Integer tenantId, @RequestParam LocalDateTime beginTime) {
        Assert.notNull(tenantId, "tenant id is required ");
        Assert.notNull(beginTime, "begin time is required ");
        return this.syncService.manualSync(tenantId, beginTime);
    }

    @GetMapping(path = "manual/tickets")
    public Flux<Object> manualSyncTickets(@RequestParam Integer tenantId) {
        Assert.notNull(tenantId, "tenant id is required ");
        return this.syncService.manualSyncTickets(tenantId);
    }


}
